//
//  EquipmenCell.m
//  DataStatistics
//
//  Created by Kang on 15/12/10.
//  Copyright © 2015年 YTYangK. All rights reserved.
//

#import "EquipmenCell.h"

@interface EquipmenCell ()

/** 设备型号 */
@property (strong, nonatomic) IBOutlet UILabel *equipmen;
/** 地区 */
@property (strong, nonatomic) IBOutlet UILabel  *area;
@property (weak, nonatomic) IBOutlet UIImageView *stateimage;
// 效率按钮
@property (weak, nonatomic) IBOutlet UIButton *efficiencyBtn;
// 效率背景
@property (weak, nonatomic)IBOutlet UIView *efficiencyBgView;
// 控制背景高度
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *efficiencyH;
// 值
@property (strong, nonatomic) IBOutlet UIButton *efficiencyVlueBtn;
// 三角形标记
@property (strong, nonatomic) IBOutlet UIImageView *triangleSign;

@end


@implementation EquipmenCell

- (void)awakeFromNib {
    // Initialization code
    if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"568.0")) {
        self.ImgR1.constant = 10;
    }else if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"667.0")){
        self.ImgR1.constant = 20;
    }
}



//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//    
//    // Configure the view for the selected state
//}

#pragma mark -设置Cell数据
- (void)setvalueWithList:(EListModel *)List {
    if (List != nil) {
        
        self.backgroundColor = RGB(33, 38, 44, 1);
        self.equipmen.text  = [NSString stringWithFormat:@"设备：%@",List.device_name];
        self.area.text  = [NSString stringWithFormat:@"值班：%@",List.employee_name];
        if (List.state ==1) {
            self.stateimage.image = [UIImage imageNamed:@"unlock"];
            [self.stateimage setAnimationImages:@[[UIImage imageNamed:@"unlock"],[UIImage  imageNamed:@"unlock_flicker"]]];
            [self.stateimage setAnimationRepeatCount:-1];
            [self.stateimage setAnimationDuration:2.5];
            [self.stateimage startAnimating];
        }else{
            self.stateimage.image = [UIImage imageNamed:@"break"];
        }
        
        [self efficiency:List.efficiency];
        
    }
    
}


- (void)efficiency:(int)viewHeight {
    
    
    if (viewHeight <70) { //红
        
        [self.efficiencyBgView setBackgroundColor:UIColorFromRGB(0xff0000)];
        
        [self.efficiencyVlueBtn setTitleColor:UIColorFromRGB(0xff0000) forState:UIControlStateNormal];

        [self.triangleSign setImage:[UIImage imageNamed:@"red"]];
       
    }else if (viewHeight <85){ // 黄
        
        [self.efficiencyBgView setBackgroundColor:UIColorFromRGB(0xe4b115)];
        [self.efficiencyVlueBtn setTitleColor:UIColorFromRGB(0xe4b115)forState:UIControlStateNormal];

        [self.triangleSign setImage:[UIImage imageNamed:@"yellow"]];
    }else{  //绿
        [self.efficiencyBgView setBackgroundColor:UIColorFromRGB(0x19a226)];
        [self.efficiencyVlueBtn setTitleColor:UIColorFromRGB(0x19a226) forState:UIControlStateNormal];

        [self.triangleSign setImage:[UIImage imageNamed:@"green"]];
    }
    CGFloat  vlue;
    if (viewHeight > 100) {
        vlue = 100/100.f;
    }else {
        vlue  = viewHeight/100.f ;
    }
      self.efficiencyH.constant =    (vlue * 64.f);
     [self.efficiencyVlueBtn setTitle:[NSString stringWithFormat:@"%d%%",viewHeight] forState:UIControlStateNormal];
}


/// 判断小标签是否有值
- (void)judgeBtnVlue:(int)btnVlue isDetermineClick:(BOOL)click {
    if (click) {
          self.btnVlue.hidden = click;
        [self.btnVlue setTitle:[NSString stringWithFormat:@"0"] forState:UIControlStateNormal];
    }else {
        if (btnVlue != 0) {
            self.btnVlue.hidden = NO;
            if (btnVlue > 99) {
                if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"736.0")) {
                    self.BtnH.constant = 21;
                    self.BtnW.constant = 29;
                    self.btnVlue.titleLabel.font = [UIFont systemFontOfSize: 13];
                    
                }else {
                    self.BtnH.constant = 18;
                    self.BtnW.constant = 28;
                    self.btnVlue.titleLabel.font = [UIFont systemFontOfSize: 11.5];
                
                }
                [self.btnVlue setTitle:[NSString stringWithFormat:@"99+"] forState:UIControlStateNormal];
                [self.btnVlue setBackgroundImage:[UIImage imageNamed:@"icon-hongdian2"] forState:UIControlStateNormal];

            }else{
                if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"568.0")) {
                    self.BtnH.constant = 22;
                    self.BtnW.constant = 22;
                    self.btnVlue.titleLabel.font = [UIFont systemFontOfSize: 11];

                }else if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"667.0")){
                    self.BtnH.constant = 20;
                    self.BtnW.constant = 20;
                    self.btnVlue.titleLabel.font = [UIFont systemFontOfSize: 12];
                    
                }else if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"736.0")){
                    self.BtnH.constant = 22;
                    self.BtnW.constant = 22;
                    self.btnVlue.titleLabel.font = [UIFont systemFontOfSize: 13];
                }
            
                [self.btnVlue setTitle:[NSString stringWithFormat:@"%d",btnVlue] forState:UIControlStateNormal];
                [self.btnVlue setBackgroundImage:[UIImage imageNamed:@"icon-hongdian"] forState:UIControlStateNormal];
            }
        }else {
            self.btnVlue.hidden = YES;
        }
    }
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"the textView content is change!!");
}


- (IBAction)efficiencyA:(UIButton *)sender {
    NSLog(@"打印看看");
}





@end
